import { messages } from "share/common";
import React, { Component } from "react";
import { Button, Form, Spin, Input, Checkbox, Affix } from "antd";
import AirServer from "../airline-server";
import { message } from "antd/lib/index";

const FormItem = Form.Item;
const TextArea = Input.TextArea;
const Group = Checkbox.Group;

@Form.create()
class SetShowView extends Component {
  constructor(props) {
    super(props);
    this.state = {
      loading: false,
      settingData: {},
    };
  }

  componentWillMount() {
    this.initData();
  }

  initData = () => {
    AirServer(this)
      .getAirModelData({ companyOid: this.props.companyOID })
      .then((res) => {
        this.setState({ settingData: res.data.body }, this.props.form.resetFields);
      });
  };

  onSaveSetting = () => {
    this.props.form.validateFieldsAndScroll((err, values) => {
      if (!err) {
        const { settingData } = this.state;
        const params = Object.assign({}, settingData, values);
        params.companyOid = this.props.companyOID;
        params.showMyTravelWay = params.showMyTravelWay.join(",");
        AirServer(this)
          .saveAirModelData(params)
          .then((res) => {
            if (res.data.success) {
              this.initData();
              message.success(messages("supplier-1.key355") /*保存成功*/);
            } else {
              message.error(res.data.message);
            }
          });
      }
    });
  };

  render() {
    const { loading, settingData } = this.state;
    const { getFieldDecorator, getFieldValue } = this.props.form;
    const isEnabledCreateOrderWarn =
      typeof getFieldValue("isEnabledCreateOrderWarn") !== "undefined"
        ? getFieldValue("isEnabledCreateOrderWarn")
        : settingData.isEnabledCreateOrderWarn;
    const isEnabledRefundChangeOrderWarn =
      typeof getFieldValue("isEnabledRefundChangeOrderWarn") !== "undefined"
        ? getFieldValue("isEnabledRefundChangeOrderWarn")
        : settingData.isEnabledRefundChangeOrderWarn;
    return (
      <div className="airline-config-container">
        <Spin className="spin" spinning={loading}>
          <Form>
            <h2>{messages("supplier-1.key393") /*首页显示我的差旅模块*/}</h2>
            <a className="a-line-bottom">
              {messages("supplier-1.key394") /*启用后，可在首页展示最近审批通过的差旅申请单*/}
            </a>
            <FormItem>
              {getFieldDecorator("showMyTravelWay", {
                initialValue: settingData.showMyTravelWay ? settingData.showMyTravelWay.split(",") : [],
              })(
                <Group>
                  <Checkbox value="1001">{messages("supplier-1.key395") /*启用国内行程*/}</Checkbox>
                  <Checkbox value="1002">{messages("supplier-1.key396") /*启用国际行程*/}</Checkbox>
                </Group>
              )}
            </FormItem>
            <br />
            <br />
            <h2>{messages("supplier-1.key397") /*首页隐藏机票查询模块*/}</h2>
            <a className="a-line-bottom">{messages("supplier-1.key398") /*启用后，可隐藏首页机票查询*/}</a>
            <FormItem>
              {getFieldDecorator("enabledHideQuery", {
                initialValue: settingData.enabledHideQuery,
                valuePropName: "checked",
              })(<Checkbox>{messages("supplier-1.key35") /*启用temp*/}</Checkbox>)}
            </FormItem>
            <br />
            <br />
            <h2>___77105_首页增加机票询价Tab页___</h2>
            <a className="a-line-bottom">___77105_启用后首页可展示机票询价Tab页___</a>
            <FormItem>
              {getFieldDecorator("enabledRfpModule", {
                initialValue: settingData.enabledRfpModule,
                valuePropName: "checked",
              })(<Checkbox>{messages("supplier-1.key35") /*启用temp*/}</Checkbox>)}
            </FormItem>
            <br />
            <br />
            <h2>{messages("supplier-1.key399") /*页尾文案*/}</h2>
            <a className="a-line-bottom">{messages("supplier-1.key400") /*可自行配置页面底部文案*/}</a>
            <FormItem>
              {getFieldDecorator("pageFootText", {
                initialValue: settingData.pageFootText || "",
              })(<Input placeholder={messages("supplier-1.key103") /*请输入temp2*/} />)}
            </FormItem>
            <br />
            <br />
            <h2>{messages("supplier-1.key401") /*国内机票政策*/}</h2>
            <a className="a-line-bottom">{messages("supplier-1.key402") /*配置后，可在机票首页展示公司差旅政策*/}</a>
            <FormItem>
              {getFieldDecorator("travelStandard", {
                initialValue: settingData.travelStandard || "",
              })(<TextArea rows={4} placeholder={messages("supplier-1.key103") /*请输入temp2*/} />)}
            </FormItem>
            <br />
            <br />
            <h2>{messages("supplier-1.key403") /*国际机票政策*/}</h2>
            <a className="a-line-bottom">{messages("supplier-1.key402") /*配置后，可在机票首页展示公司差旅政策*/}</a>
            <FormItem>
              {getFieldDecorator("intTravelStandard", {
                initialValue: settingData.intTravelStandard || "",
              })(<TextArea rows={4} placeholder={messages("supplier-1.key103") /*请输入temp2*/} />)}
            </FormItem>
            <br />
            <br />
            <h2>{messages("supplier-1.key539") /*机票预订下单页自定义提示*/}</h2>
            <a className="a-line-bottom">
              {messages("supplier-1.key540") /*可依据公司差旅政策，在下单页为员工进行提示*/}
            </a>
            <FormItem>
              {getFieldDecorator("isEnabledCreateOrderWarn", {
                initialValue: settingData.isEnabledCreateOrderWarn,
                valuePropName: "checked",
              })(<Checkbox>{messages("common.status.enable") /*启用*/}</Checkbox>)}
            </FormItem>
            {isEnabledCreateOrderWarn && (
              <FormItem>
                {getFieldDecorator("createOrderWarnText", {
                  initialValue: settingData.createOrderWarnText || "",
                  rules: [
                    {
                      required: true,
                      message: messages("supplier-1.key193") /*必填*/,
                    },
                  ],
                })(<TextArea rows={4} placeholder={messages("supplier-1.key541") /*请输入差旅政策*/} />)}
              </FormItem>
            )}
            <br />
            <br />
            <h2>{messages("supplier-1.key542") /*机票退改签申请提交页自定义提示*/}</h2>
            <a className="a-line-bottom">
              {messages("supplier-1.key543") /*可依据公司差旅政策，在机票退改签申请提交页为员工进行提示*/}
            </a>
            <FormItem>
              {getFieldDecorator("isEnabledRefundChangeOrderWarn", {
                initialValue: settingData.isEnabledRefundChangeOrderWarn,
                valuePropName: "checked",
              })(<Checkbox>{messages("common.status.enable") /*启用*/}</Checkbox>)}
            </FormItem>
            {isEnabledRefundChangeOrderWarn && (
              <FormItem>
                {getFieldDecorator("refundChangeOrderWarnText", {
                  initialValue: settingData.refundChangeOrderWarnText || "",
                  rules: [
                    {
                      required: true,
                      message: messages("supplier-1.key193") /*必填*/,
                    },
                  ],
                })(<TextArea rows={4} placeholder={messages("supplier-1.key541") /*请输入差旅政策*/} />)}
              </FormItem>
            )}
          </Form>
          <br />
          <br />
          <br />
          <br />
          <br />
          <br />
        </Spin>
        <Affix offsetBottom={0} className="setting-fotter-class">
          <Button style={{ marginLeft: 20 }} type="primary" onClick={this.onSaveSetting}>
            {messages("supplier-1.key356") /* 保存配置*/}
          </Button>
        </Affix>
      </div>
    );
  }
}

export default SetShowView;
